package team.ttorder.ttorder.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import team.ttorder.ttorder.dao.TableMapper;
import team.ttorder.ttorder.javabean.PageBean;
import team.ttorder.ttorder.model.Food;
import team.ttorder.ttorder.model.Table;

@Service
public class TableServiceimpl implements ITableService{
	
	@Autowired
	private TableMapper tableMapper;
	
	/**
	 * 查找所有的餐桌,并且封装到PageBean类中
	 */
	@Override
	public PageBean<Table> selectAll(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Table> list = tableMapper.selectAll();
		return new PageBean<Table>(list);
	}
	
	/**
	 * 查找所有的餐桌
	 */
	@Override
	public List<Table> findAllTables() {
		return tableMapper.selectAll();
	}

	/**
	 * 查找餐桌的ID
	 */
	@Override
	public Table selectTableById(int id) {
		
		return tableMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查找同一状态下所有餐桌
	 */
	@Override
	public List<Table> selectTablesStatus(int tablesStatus) {
		
		return tableMapper.selectTablesStatus(tablesStatus);
	}

	/**
	 * 添加餐桌
	 */
	@Override
	public void addTable(Table table) {
		tableMapper.insert(table);
	}

	/**
	 * 更新餐桌
	 */
	@Override
	public void updaTetable(Table table) {
		
		tableMapper.updateByPrimaryKey(table);
	}

	/**
	 * 删除餐桌
	 */
	@Override
	public void deleteTable(int id) {
		
		tableMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Food> selectFood(int foodTypeId) {
		
		return tableMapper.selectFoot(foodTypeId);
	}
	
}
